package Dom;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

public class Dom4j {

	public static void main(String[] args) {
		SAXReader read = new SAXReader();
		try {
			Document document = read.read("sample.xml");
			Element root = document.getRootElement();
			for(Object obj:root.elements()){
				Element child =(Element)obj;
				if(!"student".equals(child.getName())){
					continue;
				}
				System.out.println("===========student=================");
				System.out.println("age "+child.elementText("age"));
				System.out.println("name "+child.elementText("name"));
				System.out.println("gender "+child.elementText("gender"));
				System.out.println("id "+child.attributeValue("id"));
			}
		} catch (DocumentException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
